<template>
  <div class="info">
    <div>
      <el-image
        class="image"
        :src="image"
      ></el-image>
    </div>
    <div>
      <div class="title">
        {{ commodityName }}
      </div>
      <div class="price">
        <div style="height: 40px; line-height: 40px">
          <!-- margin: 0 10px; -->
          <span style="font-size: 16px; font-weight: 100; margin-right: 10px; color: #999999">价 格</span>
          <span style="font-size: 16px; margin-right: 2px; color: #e4393c">￥</span>
          <span style="font-size: 20px; color: #e4393c"> {{ price }}</span>
        </div>
      </div>
      <el-divider></el-divider>
      <div style="font-size: 16px; font-weight: 100; color: #999999; align-items: center; display: flex; flex-direction: row;">
        配 送 至
        <address-select></address-select> {{ inventory > 0 ? "有货" : "无货" }}
      </div>
      <el-divider></el-divider>
      <div>
        <el-input-number
          style="width: 100px; margin-right: 10px;"
          v-model="number"
          :min="1"
          controls-position="right"
        ></el-input-number>
        <el-button
          style="background-color: #3271ae; color: #fff;"
          @click="doShoppingCartAdd"
        >加入购物车</el-button>
      </div>
    </div>
  </div>
</template>

<script>
import AddressSelectVue from "./AddressSelect.vue";
import { shoppingCartAdd } from "@/api/shoppingCart";
import { ElMessage } from "element-plus";

export default {
  props: {
    commodityId: Number,
    price: Number,
    commodityName: String,
    image: String,
    inventory: Number,
  },
  components: {
    AddressSelect: AddressSelectVue,
  },
  data() {
    return {
      address: "江苏省",
      number: 1,
    };
  },
  methods: {
    doShoppingCartAdd() {
      shoppingCartAdd(this.commodityId, this.number).then((res) => {
        ElMessage({
          message: "加入购物车成功",
          type: "success",
        });
      });
    },
  },
};
</script>

<style scoped>
.info {
  display: flex;
  justify-content: center;
  margin: 20px 0;
}

.image {
  width: 400px;
  height: 400px;
  margin: 0 20px;
}

.price {
  width: 650px;
  height: 200px;
  /* background-color: #fafafa; */
  margin-top: 20px;
}

.title {
  width: 650px;
  font-size: 18px;
  font-weight: 900px;
  color: #666666;
}
</style>